Page({
  data: {
    cardCur: 0,
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://img0.baidu.com/it/u=655843868,2134969863&fm=253&fmt=auto&app=138&f=PNG?w=650&h=407'
    }, {
      id: 1,
        type: 'image',
        url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.ypiq.cn%2Fwp-content%2Fuploads%2F2020%2F05%2F0215352200-1.jpg&refer=http%3A%2F%2Fwww.ypiq.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1658508270&t=1f1bfe97f9935baa9bd1348f4c06680e',
    }, {
      id: 2,
      type: 'image',
      url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.mianfeiwendang.com%2Fpic%2Ffc530f6b8386a4f3d5c1748ca27a6a06ed7ba105%2F1-329-png_6_0_0_102_378_690_493_892.5_1263-460-0-0-460.jpg&refer=http%3A%2F%2Fwww.mianfeiwendang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1658508226&t=8f09cfd739e07d1cc562855b77ffcf62'
    }, {
      id: 3,
      type: 'image',
      url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ffile.xdf.cn%2Fuploads%2F190618%2F230_190618143843pFP5CDjTBjLjxYPw.jpg&refer=http%3A%2F%2Ffile.xdf.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1658508385&t=db2cccb1add69497a4b7fd464fac2106'
    }, {
      id: 4,
      type: 'image',
      url: 'https://img2.baidu.com/it/u=1424360221,1298673640&fm=253&fmt=auto&app=138&f=JPEG?w=640&h=426'
    }, {
      id: 5,
      type: 'image',
      url: 'https://img1.baidu.com/it/u=3787179988,61062692&fm=253&fmt=auto&app=138&f=JPEG?w=779&h=500'
    }, {
      id: 6,
      type: 'image',
      url: 'https://img1.baidu.com/it/u=2994698921,984292314&fm=253&fmt=auto&app=120&f=JPEG?w=700&h=466'
    
    }],
    
  },
  onLoad() {
    this.towerSwiper('swiperList');
    // 初始化towerSwiper 传已有的数组名即可
  },
  DotStyle(e) {
    this.setData({
      DotStyle: e.detail.value
    })
  },
  // cardSwiper
  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  // towerSwiper
  // 初始化towerSwiper
  towerSwiper(name) {
    let list = this.data[name];
    for (let i = 0; i < list.length; i++) {
      list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
      list[i].mLeft = i - parseInt(list.length / 2)
    }
    this.setData({
      swiperList: list
    })
  },
  // towerSwiper触摸开始
  towerStart(e) {
    this.setData({
      towerStart: e.touches[0].pageX
    })
  },
  // towerSwiper计算方向
  towerMove(e) {
    this.setData({
      direction: e.touches[0].pageX - this.data.towerStart > 0 ? 'right' : 'left'
    })
  },
  // towerSwiper计算滚动
  towerEnd(e) {
    let direction = this.data.direction;
    let list = this.data.swiperList;
    if (direction == 'right') {
      let mLeft = list[0].mLeft;
      let zIndex = list[0].zIndex;
      for (let i = 1; i < list.length; i++) {
        list[i - 1].mLeft = list[i].mLeft
        list[i - 1].zIndex = list[i].zIndex
      }
      list[list.length - 1].mLeft = mLeft;
      list[list.length - 1].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    } else {
      let mLeft = list[list.length - 1].mLeft;
      let zIndex = list[list.length - 1].zIndex;
      for (let i = list.length - 1; i > 0; i--) {
        list[i].mLeft = list[i - 1].mLeft
        list[i].zIndex = list[i - 1].zIndex
      }
      list[0].mLeft = mLeft;
      list[0].zIndex = zIndex;
      this.setData({
        swiperList: list
      })
    }
  }
 
})
